package com.avic.map.common.model;

import com.avic.map.common.constant.LocalResourceConstant;
import com.avic.map.common.model.enums.MapDataStatusEnums;
import com.avic.map.common.queue.receive.RabbitMqReceiver;
import com.avic.map.dal.model.CarResource;
import com.avic.map.dal.model.ShipStaticInfo;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class MapCommonModel implements Serializable {

    private static final long serialVersionUID = 7354858572319302201L;
    /**
     * 维度
     */
    private double latitude;

    /**
     * 经度
     */
    private double longitude;

    /**
     * 方向
     */
    private double direction;

    /**
     * 状态
     */
    private int status;

    /**
     * 数据ID
     */
    private String modelId;

    /**
     * 数据时间戳
     */
    private long dataTime;

    /**
     * 数据时间字符串
     */
    private String dataTimeString;

    /**
     * 数据下标
     */
    private int modelIndex = 0;

    /**
     * 是否移除
     */
    private boolean remove = false;

    /**
     * 资源名称
     */
    private String modelName;

    /**
     * 船舶静态信息
     */
    private ShipStaticInfo shipStaticInfo;

    /**
     * 车辆静态信息对象
     */
    private CarResource carResourceInfo;

    /**
     * 速度
     */
    private double speed;

    public MapCommonModel() {
    }

    private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public MapCommonModel(VdmShipPositionModel vdmShipPositionModel) {

        // 转换地图数据
        this.setDirection(vdmShipPositionModel.getCourseOverGround());
        this.setLatitude(vdmShipPositionModel.getGcj().getWgLat());
        this.setLongitude(vdmShipPositionModel.getGcj().getWgLon());
        this.setModelId(String.valueOf(vdmShipPositionModel.getMmsi()));
        this.setDataTime(vdmShipPositionModel.getDateTime());
        Date date = new Date(vdmShipPositionModel.getDateTime());
        this.setDataTimeString(simpleDateFormat.format(date));
        this.setStatus(MapDataStatusEnums.VIDM.getType());
        ShipStaticInfo shipStaticInfo = LocalResourceConstant.VDM_SHIP_STATE_DB_MAP.get(String.valueOf(vdmShipPositionModel.getMmsi()));
        if (null != shipStaticInfo) {
            this.setModelName(shipStaticInfo.getShipName());
            this.setShipStaticInfo(shipStaticInfo);
        } else {
            this.setModelName(StringUtils.EMPTY);
            this.setShipStaticInfo(RabbitMqReceiver.shipStaticInfo);
        }
        this.setSpeed(vdmShipPositionModel.getSpeedOverGround());
    }

    public MapCommonModel(ShipPositionModel shipPositionModel, MapDataStatusEnums mapDataStatusEnums, ShipStaticInfo shipStaticInfo) {
        this.setDirection(shipPositionModel.getCog());
        this.setLatitude(shipPositionModel.getGcj().getWgLat());
        this.setLongitude(shipPositionModel.getGcj().getWgLon());
        this.setModelId(String.valueOf(shipPositionModel.getMmsi()));
        this.setDataTime(shipPositionModel.getDateTime());
        Date date = new Date(shipPositionModel.getDateTime());
        this.setDataTimeString(simpleDateFormat.format(date));
        this.setStatus(mapDataStatusEnums.getType());
        if (null != shipStaticInfo) {
            this.setModelName(shipStaticInfo.getShipName());
            this.setShipStaticInfo(shipStaticInfo);
        } else {
            this.setModelName(StringUtils.EMPTY);
            this.setShipStaticInfo(RabbitMqReceiver.shipStaticInfo);
        }
        this.setSpeed(shipPositionModel.getSog());
    }

    public MapCommonModel(GpsCarModel gpsCarModel, CarResource carResource) {
        this.setDirection(0);
        this.setLatitude(gpsCarModel.getGcj().getWgLat());
        this.setLongitude(gpsCarModel.getGcj().getWgLon());
        this.setModelId(gpsCarModel.getTarget().getNumber());
        this.setDataTime(gpsCarModel.getDateTime());
        Date date = new Date(gpsCarModel.getDateTime());
        this.setDataTimeString(simpleDateFormat.format(date));
        this.setModelName(carResource.getCarType());
        if (null != carResource) {
            this.setCarResourceInfo(carResource);
        } else {
            this.setCarResourceInfo(new CarResource());
        }
    }

    public MapCommonModel(GpsCarModel gpsCarModel, String resourceName) {
        this.setDirection(0);
        this.setLatitude(gpsCarModel.getGcj().getWgLat());
        this.setLongitude(gpsCarModel.getGcj().getWgLon());
        this.setModelId(gpsCarModel.getTarget().getNumber());
        this.setDataTime(gpsCarModel.getDateTime());
        Date date = new Date(gpsCarModel.getDateTime());
        this.setDataTimeString(simpleDateFormat.format(date));
        this.setModelName(resourceName);
    }

    public MapCommonModel(SoldierModel soldierModel) {
        this.setDirection(0);
        this.setLatitude(soldierModel.getGps().getWgLat());
        this.setLongitude(soldierModel.getGps().getWgLon());
        this.setModelId(soldierModel.getDevid());
        this.setDataTime(soldierModel.getDataTime());
        Date date = new Date(soldierModel.getDataTime());
        this.setDataTimeString(simpleDateFormat.format(date));
        this.setModelName(LocalResourceConstant.SOLDIER_STATE_DB_MAP.get(soldierModel.getDevid()).getPersonnelCompany());
    }

}


